package la.iok.hzsvn.lewin.movie.shopmovie.model;

import la.iok.hzsvn.lewin.movie.core.model.SimpleOrgUnitVo;
import la.iok.hzsvn.lewin.movie.core.model.SimpleUser;
import la.iok.hzsvn.share.collection.IdOperators;
import la.iok.hzsvn.share.phone.PhoneNumberUtils;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 发车量和推客量统计报表
 */
public class CarpoolReport {
    /**
     * 查询指定店铺的数据
     */
    private Long orgUnitId;

    /**
     * 查询指定人员拼车数量：userID 查询指定ID,null：不以此作过滤条件
     */
    private Long userId;
    /**
     * 统计开始时间
     */
    private Date start;
    /**
     * 统计结束时间
     */
    private Date end;
    /**
     * 拼车状态过滤
     */
    private Integer status;
    /**
     * 是否确认。0：查未确认的，1：查已确认的，null：不以此作过滤条件
     */
    private Integer confirmed;
    /**
     * 统计的记录
     */
    private List<CarpoolReportCount> records;

    public Long getOrgUnitId() {
        return orgUnitId;
    }

    public void setOrgUnitId(Long orgUnitId) {
        this.orgUnitId = orgUnitId;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getConfirmed() {
        return confirmed;
    }

    public void setConfirmed(Integer confirmed) {
        this.confirmed = confirmed;
    }

    public List<CarpoolReportCount> getRecords() {
        return records;
    }

    public void setRecords(List<CarpoolReportCount> records) {
        this.records = records;
    }

    public void fillRecords(List<CarpoolReportCount> list, List<SimpleOrgUnitVo> orgUnits, List<SimpleUser> users){
        list.forEach(item->{
            SimpleOrgUnitVo orgUnit = IdOperators.find(orgUnits, item.getOrgUnitId());
            if(orgUnit != null){
                item.setOrgUnitName(orgUnit.getName());
            }
            SimpleUser user = IdOperators.find(users, item.getUserId());
            if(user != null){
                item.setUserNickname(user.getNickname());
                item.setUserPhoneNumber(PhoneNumberUtils.encPhoneNumber(user.getPhoneNumber()));
            }
        });
        setRecords(list);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CarpoolReport)) return false;
        CarpoolReport report = (CarpoolReport) o;
        return Objects.equals(orgUnitId, report.orgUnitId) && Objects.equals(start, report.start) && Objects.equals(end, report.end) && Objects.equals(status, report.status) && Objects.equals(confirmed, report.confirmed) && Objects.equals(records, report.records);
    }

    @Override
    public int hashCode() {
        return Objects.hash(orgUnitId, start, end, status, confirmed, records);
    }

    @Override
    public String toString() {
        return "CarpoolReport{" +
                "orgUnitId=" + orgUnitId +
                ", start=" + start +
                ", end=" + end +
                ", status=" + status +
                ", confirmed=" + confirmed +
                ", records=" + records +
                '}';
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }
}
